﻿using System;
using System.Web;

public partial class UI_Mail_Config : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
            System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");

            txtAddress.Value = config.AppSettings.Settings["EmailSystem.Address"].Value;
            txtEmail.Value = config.AppSettings.Settings["EmailSystem.Email"].Value;
            txtDays.Value = config.AppSettings.Settings["EmailSystem.Days"].Value;
        }
    }

    public void ButtonSave_Click(object sender, EventArgs e) {
        String address = txtAddress.Value;
        String email = txtEmail.Value;
        String days = txtDays.Value;

        try {
            System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
            config.AppSettings.Settings["EmailSystem.Address"].Value = address;
            config.AppSettings.Settings["EmailSystem.Email"].Value = email;
            config.AppSettings.Settings["EmailSystem.Days"].Value = days;
            config.Save();
        } catch (System.Exception ex) {
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "days", "<script>alert('保存设置出错, 错误代码: " + ex.Message.Replace("\r\n", " ") + "...')</script>");
            //retMsg = "保存设置出错, 错误代码: " + ex.Message.Replace("\r\n", " ") + "...";
        }
    }
}